$(function () {
    
    //渲染最新
    $.ajax({
        url: 'http://localhost:3000/play/new',
        type: 'get',
        success(res) {
            for (let item of res) {
                for (let i = 0; i < item.length; i++) {
                    var str = $(`
                    <div class="prdItem prdItemKw">
                    <img src="${item[i].img}" alt="">
                    <p>${item[i].text}</p>
                    <div class="author">
                        <span class="price">${item[i].price}</span>
                        <div class="zan">
                            <span><img src="./img/xinRedo.png" alt="">3</span>
                            <span><img src="./img/reply.png" alt="">3</span>
                        </div>
                    </div>
                </div>
                    `)
                    $('.products01').append(str);
                }
            }
        }
    })
    //渲染最热
    $.ajax({
        url: 'http://localhost:3000/play/hot',
        type: 'get',
        success(res) {
            // console.log(res);
            for (let item of res) {
                for (let i = 0; i < item.length; i++) {
                    var str = $(`
                        <div class="prdItem prdItemKw">
                        <img src="${item[i].img}" alt="">
                        <p>${item[i].text}</p>
                        <div class="author">
                            <span class="price">${item[i].price}</span>
                            <div class="zan">
                                <span><img src="./img/xinRedo.png" alt="">3</span>
                                <span><img src="./img/reply.png" alt="">3</span>
                            </div>
                        </div>
                    </div>
                        `)
                    $('.products02').prepend(str);
                }
            }
        }
    })
    // 渲染品类
    $.ajax({
        url: 'http://localhost:3000/play/category',
        type: 'get',
        success(res) {
            $(res).each(function(i,item){
                let arr1=['.lf p','.huli p','.chuandai p','.chuxing p','.huwai p','.jiadian p']
                $('.life h4').eq(i).text(item.title);
                $.each(item.list,function(a,ad){
                    // console.log(a,ad);
                    $(arr1[i]).eq(a).text(ad.productName)
                    // debugger
                })
                
            })
        }
    })

    //tab切换
    $('.tabBtn').on('click', function () {
        $(this).addClass('current').siblings().removeClass('current');
        $(this).children().addClass('color')
        $(this).siblings().children().removeClass('color');
        var index = $(this).index();
        $('.kwBox01').eq(index).stop().fadeIn().siblings().stop().fadeOut();
    })
})